package org.linlinjava.litemall.wx.filter;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.regex.Pattern;

/**
 * @author: weilai 过滤器拦截信息..获取请求地址
 * @date: 2019/12/26
 * @description:
 */
@Slf4j
public class TraceStreamFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("StreamFilter初始化...");
    }

    private final static String commodity_URL= "/wx/commodity/\\*\\*";
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//        if (!Pattern.matches(commodity_URL, requestURI)) {
//            chain.doFilter(request, response);
//            return;
//        }
        ServletRequest requestWrapper = new TraceWrapper((HttpServletRequest) request);
        chain.doFilter(requestWrapper, response);
    }
    @Override
    public void destroy() {
        log.info("StreamFilter销毁...");
    }
}